﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunnyFunction
{
    public class GusNum
    {
        public static void Start()
        {
            var g1 = new int[] { 1, 2, 3, 4 };
            var g2 = new int[] { 2, 1, 5, 6 };
            var g3 = new int[] { 7, 8, 1, 2 };
            List<int> tList= new List<int>();
            for (int i = 0; i < 1000; i++)
            {
                var source = GetArr();
                CheckNum(source, g1, out int A1, out int B1);
                CheckNum(source, g2, out int A2, out int B2);
                CheckNum(source, g3, out int A3, out int B3);

                int at = A1 + A2 + A3;
                if (at == 4)
                {
                    Console.WriteLine(string.Join(",", source));
                }
                tList.Add(at);
            }

            var gp = tList.GroupBy(t => t);
            foreach (var g in gp)
            {
                Console.WriteLine($"Total: {g.Key} => {g.Count()}");
            }
        }

        private static void CheckNum(int[] source, int[] guess, out int A, out int B)
        {
            A = 0;
            B = 0;

            for (int i = 0; i < 4; i++)
            {
                int b = guess[i];
                var a = source[i];
                if (b == a)
                    A++;
                else if (source.Contains(b))
                {
                    B++;
                }
            }
        }

        private static int[] GetArr()
        {
            List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[] re = new int[4];

            Random rand = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < 4; i++)
            {
                var index = rand.Next(0, list.Count);
                re[i] = list[index];
                list.RemoveAt(index);
            }

            return re;
        }
    }
}
